package com.webmall.servlet.cate;

import com.webmall.entity.CateEntity;
import com.webmall.entity.UserEntity;
import com.webmall.service.webmall_CateDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

import static com.webmall.service.webmall_UserDao.updateById;

@WebServlet("/manageHtml/admin_doCateModify")
public class doCateModify extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //设置字符集
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");

        //根据add界面的name参数进行内容获取
        int id = Integer.parseInt(request.getParameter("id"));
        int parentId = Integer.parseInt(request.getParameter("parentId"));
        String name = request.getParameter("name");

        CateEntity cate = new CateEntity(id,name,parentId);


        //加入数据库的表中
        int count= webmall_CateDao.updateCate(cate);


        //成功或失败重定位到哪儿
     if (count >0){
            response.sendRedirect(request.getContextPath()+"/manageHtml/admin_CateSelect");//修改成功 返回到当前页


        }else {//失败 用输出流输出 js语句
            PrintWriter out = response.getWriter();
            out.write("<script>");
            out.write("alert('用户修改失败')");
            out.write("location.href='/manageHtml/admin_CateSelect？'");
            out.write("</script>");

        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
